package com.yoda.mall.admin.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yoda.mall.api.FlashPromotionApi;
import com.yoda.mall.model.entity.sms.Coupon;
import com.yoda.mall.model.entity.sms.FlashPromotion;
import com.yoda.mall.model.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

@Service
public class FlashService {
    @DubboReference
    private FlashPromotionApi flashPromotionApi;
    public void createFlash(FlashPromotion flashPromotion) {
        flashPromotionApi.createFlash(flashPromotion);
    }

    public void deleteFlash(Long id) {
        flashPromotionApi.deleteFlashById(id);
    }

    public PageResult<FlashPromotion> flashListPage(String keyword, Integer pageNum, Integer pageSize) {
        Page<FlashPromotion> page = flashPromotionApi.getFlashPromotionListPage(keyword, pageNum, pageSize);
        return new PageResult<>((int) page.getCurrent(), (int) page.getSize(), (int) page.getTotal(), page.getRecords());
    }

    public void updateFlashPromotionStatus(Long id, Integer status) {
        FlashPromotion flashPromotion = new FlashPromotion();
        flashPromotion.setId(id);
        flashPromotion.setStatus(status);
        flashPromotionApi.updateFlashPromotionStatus(flashPromotion);
    }

    public void updateFlashPromotion(Long id, FlashPromotion flashPromotion) {
        flashPromotion.setId(id);
        flashPromotionApi.updateFlashPromotion(flashPromotion);
    }

    public FlashPromotion getFlashPromotion(Long id) {
        return flashPromotionApi.getFlashPromotionById(id);
    }
}
